package homework.homework05;

public class Test05 {
    public static void main(String[] args) {
        Book[] bs = new Book[3];
        bs[0] = new Book("0011", "三国演义", 50);
        bs[1] = new Book("0012", "红楼梦", 60);
        bs[2] = new Book("0013", "水浒传", 40);
        System.out.println(maxBook(bs));
    }
    //对图书数组，按照价格冒泡排序，从小到大，返回价格最高的图书对象
    public static Book maxBook(Book[] bs) {
        for (int i = 0; i < bs.length - 1; i++) {
            for (int j = 0; j < bs.length - 1 - i; j++) {
                if (bs[j].getPrice() > bs[j + 1].getPrice()) {
                    Book temp = bs[j];
                    bs[j] = bs[j + 1];
                    bs[j + 1] = temp;
                }
            }
        }
        return bs[bs.length - 1];
    }
}
